package com.customer.mall.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.customer.mall.domain.Banner;
import com.customer.mall.domain.vo.BannerVO;
import com.customer.mall.service.IBannerService;
import com.customer.mall.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author BaiGGG
 * @since 2023-06-25
 */
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private IBannerService bannerService;

    @GetMapping("/list")
    public ResponseResult<Page<BannerVO>> pageBanner(@RequestParam(defaultValue = "1") Integer pageNum,
                                                     @RequestParam(defaultValue = "5") Integer pageSize) {
        return bannerService.pageBanner(pageNum, pageSize);
    }

    @GetMapping("/state")
    public ResponseResult<String> setState(Integer id){
        return bannerService.setState(id);
    }


    @GetMapping("/admin/{id}")
    public ResponseResult<BannerVO> getBannerById(@PathVariable Integer id){
        return bannerService.getBannerById(id);
    }

    @GetMapping("/admin/all/{id}")
    public ResponseResult<Banner> getBannerAllById(@PathVariable Integer id){
        return bannerService.getBannerAllById(id);
    }


    @PostMapping("/admin/insert")
    public ResponseResult<String> insertBanner(@RequestBody Banner banner){
        return bannerService.insertBanner(banner);
    }

    @PostMapping("/admin/update")
    public ResponseResult<String> updateBanner(@RequestBody Banner banner){
        return bannerService.updateBanner(banner);
    }



    @PostMapping("/admin/delete")
    public ResponseResult<String> deleteBanner(@RequestBody List<Integer> ids){
        return bannerService.removeBatchByIds(ids) ? ResponseResult.okResult() : ResponseResult.failResult();
    }

}
